package cn.aitrox.ry.app.web.controller.config;

import cn.aitrox.ry.bean.CommonPageInfo;
import cn.aitrox.ry.bean.RespResult;
import cn.aitrox.ry.service.config.dto.ComponentDto;
import cn.aitrox.ry.service.config.dto.in.ComponentCreateInDto;
import cn.aitrox.ry.service.config.dto.in.ComponentEditInDto;
import cn.aitrox.ry.service.config.dto.in.ComponentSearchInDto;
import cn.aitrox.ry.service.config.feign.ComponentFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ComponentController {

    @Autowired
    @Lazy
    private ComponentFeign componentFeign;


    @PostMapping(value = "/config/component/search")
    public RespResult<CommonPageInfo<ComponentDto>> search(@RequestBody ComponentSearchInDto input) {
        CommonPageInfo<ComponentDto> pageInfo = componentFeign.search(input);
        return RespResult.ok(pageInfo);
    }

    @PostMapping(value = "/config/component")
    public RespResult create(@RequestBody ComponentCreateInDto input) {
        return componentFeign.create(input);
    }

    @PutMapping(value = "/config/component")
    public RespResult edit(@RequestBody ComponentEditInDto input) {
        return componentFeign.edit(input);
    }

    @GetMapping(value = "/config/component/{id}")
    public RespResult<ComponentDto> read(@PathVariable("id") Integer id) {
        ComponentDto component = componentFeign.read(id);
        return RespResult.ok(component);
    }
}
